<template>
  <van-datetime-picker
    v-model="currentDate"
    type="date"
    title="选择年月日"
    :min-date="minDate"
    :max-date="maxDate"
    @confirm="onoCnfirm"
    @cancel="onCancel"
  />
</template>
<script>
import { editUserProfileAPI } from '@/api/index'
import dayjs from '@/utils/dayjs'
export default {
  props: {
    birthday: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      minDate: new Date(1900, 0, 0), //最小时间
      maxDate: new Date(2022, 0, 0), //当前最大时间
      currentDate: new Date(this.birthday) //当前选中时间
    }
  },
  methods: {
    async onoCnfirm() {
      const birthday = dayjs(this.currentDate).format('YY-MM-DD')
      await editUserProfileAPI({
        birthday
      })
      this.$emit('update:birthday', birthday)
    },
    onCancel() {
      this.$emit('close')
    }
  }
}
</script>

<style></style>
